package javaapplication1;

import java.awt.Graphics;
import java.awt.Image;

public class Renderer extends Thread{
    private BoardPanel boardPanel;
    private Scene scene;
    private int time = 5;
    private Image offImage;
    private Graphics offGraphics;
    
    public Renderer(Scene tablero, BoardPanel boardPanel){
        this.scene = tablero;
        this.boardPanel = boardPanel;
        offImage = this.boardPanel.getImage();
        offGraphics = offImage.getGraphics();
    }

    private void render() {
        offGraphics.clearRect(0,0,400,300);
        scene.dibujar(offGraphics);
        
        boardPanel.setImage(offImage);
        boardPanel.repaint();
    }
    
    public void run(){
        while(true){
            render();
            try {
                Thread.sleep(time);
            } catch (InterruptedException ex) {
            }
            
        }
    }
}
